/*
 * @Author: Joel
 * @Date: 2025-04-09 16:11:28
 * @LastEditors: Joel
 * @LastEditTime: 2025-04-09 17:06:05
 * @FilePath: /gd32f303cct6/usr/board_driver/buzzer.c
 * @Description: 
 * Copyright (C) 2025 YiJiaLink, All Rights Reserved. 
 * 2025-04-09 16:11:28
 */

#include"buzzer.h"

static void buzzer_gpio_init (void);
static void run_buzzer(void);
static void stop_buzzer(void);
static struct buzzer_func buzzer;
/**
 * @func: 
 * @description: 初始化buzzer
 * @param {buzzer_func} buzzer_func
 * @return {*}
 * @example: 
 */
struct buzzer_func *buzzer_init(void)
{
    struct buzzer_func *buzzer_func = &buzzer;
    buzzer_func->init_buzzer = buzzer_gpio_init;
    buzzer_func->run_buzzer = run_buzzer;
    buzzer_func->stop_buzzer = stop_buzzer;
    return buzzer_func;
}
/**
 * @func: 
 * @description: 初始化GPIO口
 * @return {*}
 * @example: 
 */
static void buzzer_gpio_init (void)
{
    /* enable the led clock */
    rcu_periph_clock_enable(BUZZER_GPIO_CLK);
    /* configure led GPIO port */ 
    gpio_init(BUZZER_GPIO_PORT, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ,BUZZER_PIN);

    GPIO_BC(BUZZER_GPIO_PORT) = BUZZER_PIN;

    return;
}
/**
 * @func: 
 * @description: 翻转电平启动buzzer
 * @return {*}
 * @example: 
 */
static void run_buzzer(void)
{
    static uint8_t flag;
    if(RESET != flag){
        GPIO_BOP(BUZZER_GPIO_PORT) = (uint32_t)BUZZER_PIN;
    }else{
        GPIO_BC(BUZZER_GPIO_PORT) = (uint32_t)BUZZER_PIN;
    }
    flag = !flag;
    return;
}
/**
 * @func: 
 * @description: 低电平关闭buzzer
 * @return {*}
 * @example: 
 */
static void stop_buzzer(void)
{
    gpio_bit_reset(BUZZER_GPIO_PORT, BUZZER_PIN);
    return;
}

